#include "list.h"
#include "service.h"
#include <iostream>

struct list *Add_User(struct list *head,void *arg)
{
    int sockfd = *(int *)arg;
    free(arg);
    struct list *node = Add_End_Node(head);
    if(node == NULL) return NULL;
    node->sockfd = sockfd;
    node->id = sockfd;

    return node;
}

struct list *Remove_User(struct list *head,void *arg)
{
    int sockfd = *(int *)arg;
    struct list *tmp = head->next;
    while(tmp != head)
    {
        if(sockfd == tmp->sockfd)
        {
            break;
        }
        tmp = tmp->next;
    }
    if(tmp == head) return NULL;
    tmp->prev->next = tmp->next;
    tmp->next->prev = tmp->prev;
    free(tmp);
    return head;
}
